/*     */ package com.newcrm.webapi.sub;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CompanyExtManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.Hardware4Win;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.AbstractAction;
/*     */ import com.newcrm.webapi.AbstractHttpServlet;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.net.URLEncoder;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import net.sf.json.JSONObject;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ 
/*     */ public class ActiveCodeChecker extends AbstractAction
/*     */ {
/*  35 */   private boolean isSave2DB = false;
/*     */ 
/*  37 */   private static Logger logger = Logger.getLogger(ActiveCodeChecker.class
/*  38 */     .getName());
/*     */ 
/*     */   public ActiveCodeChecker()
/*     */   {
/*     */   }
/*     */ 
/*     */   public ActiveCodeChecker(AbstractHttpServlet servlet)
/*     */   {
/*  52 */     super(servlet);
/*  53 */     this.isSave2DB = false;
/*     */   }
/*     */ 
/*     */   public ActiveCodeChecker(AbstractHttpServlet servlet, boolean flag)
/*     */   {
/*  62 */     super(servlet);
/*  63 */     this.isSave2DB = flag;
/*     */   }
/*     */ 
/*     */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*     */     throws IOException, ServletException, NotFoundException
/*     */   {
/*  73 */     response.setContentType("text/html;charset=utf-8");
/*  74 */     JSONObject jsonObject = new JSONObject();
/*  75 */     PrintWriter out = response.getWriter();
/*     */ 
/*  77 */     String activeCode = Util.getURLParameter(request
/*  78 */       .getParameter("activeCode"));
/*  79 */     String companyId2 = Util.getURLParameter(request
/*  80 */       .getParameter("companyId2"));
/*  81 */     String checkCode = null;
/*     */ 
/*  83 */     Hardware4Win hardware = new Hardware4Win();
/*     */     try {
/*  85 */       checkCode = hardware.getSerialNumber();
/*     */     }
/*     */     catch (Exception ex) {
/*  88 */       checkCode = hardware.getRandomNumberUpperLetterChar(10);
/*     */     }
/*     */ 
/*  91 */     if ((activeCode == null) || (activeCode.trim().length() == 0) || 
/*  92 */       (companyId2 == null) || (companyId2.trim().length() == 0) || 
/*  93 */       (checkCode == null) || (checkCode.trim().length() == 0)) {
/*  94 */       logger.warn("activeCode, companyId2 or checkCode is null");
/*  95 */       jsonObject.put("error", "1");
/*  96 */       jsonObject.put("msg", "获取注册码等信息失败，请重新提交！");
/*  97 */       out.println(jsonObject);
/*  98 */       out.flush();
/*  99 */       out.close();
/* 100 */       return;
/*     */     }
/*     */ 
/* 103 */     StringBuffer searchUrl = new StringBuffer();
/* 104 */     searchUrl.append("http://oem.qikebao.com/activeCode?activeCode=")
/* 105 */       .append(URLEncoder.encode(activeCode, "UTF-8"))
/* 106 */       .append("&companyId2=")
/* 107 */       .append(URLEncoder.encode(companyId2, "UTF-8"))
/* 108 */       .append("&checkCode=")
/* 109 */       .append(URLEncoder.encode(checkCode, "UTF-8"));
/*     */ 
/* 111 */     response.setContentType("text/html;charset=utf-8");
/* 112 */     Document doc = null;
/*     */     try {
/* 114 */       doc = Jsoup.connect(searchUrl.toString()).timeout(30000).get();
/*     */     } catch (Exception e) {
/* 116 */       logger.warn("access url falied, url: " + searchUrl, e);
/* 117 */       jsonObject.put("error", "1");
/* 118 */       jsonObject.put("msg", "验证超时，请稍后再试" + e);
/* 119 */       out.println(jsonObject);
/* 120 */       out.flush();
/* 121 */       out.close();
/* 122 */       return;
/*     */     }
/* 124 */     JSONObject json = null;
/*     */     try {
/* 126 */       json = JSONObject.fromObject(doc.text());
/*     */     } catch (Exception e) {
/* 128 */       logger.warn("body to json failed, body: " + doc.text(), e);
/* 129 */       jsonObject.put("error", "1");
/* 130 */       jsonObject.put("msg", "验证超时，请稍后再试" + e);
/* 131 */       out.println(jsonObject);
/* 132 */       out.flush();
/* 133 */       out.close();
/* 134 */       return;
/*     */     }
/*     */ 
/* 138 */     if ("1".equals(Util.getJSONStringValue(json, "success"))) {
/* 139 */       String licenceNum = Util.getJSONStringValue(json, "licenceNum");
/* 140 */       String expiredDate = Util.getJSONStringValue(json, "expiredDate");
/* 141 */       jsonObject.put("error", "0");
/* 142 */       jsonObject.put("licenceNum", licenceNum);
/* 143 */       jsonObject.put("checkCode", checkCode);
/* 144 */       jsonObject.put("companyId2", companyId2);
/* 145 */       jsonObject.put("expiredDate", expiredDate);
/*     */ 
/* 147 */       if (this.isSave2DB)
/*     */       {
/* 149 */         User u = super.getLoginUser(request);
/* 150 */         CompanyExtManager manager = new CompanyExtManager();
/* 151 */         manager.update(16, checkCode, 
/* 152 */           u.companyId, u.userId);
/* 153 */         manager.update(18, expiredDate, 
/* 154 */           u.companyId, u.userId);
/* 155 */         manager.update(17, licenceNum, 
/* 156 */           u.companyId, u.userId);
/*     */       }
/*     */     } else {
/* 159 */       String message = Util.getJSONStringValue(json, "message");
/* 160 */       logger.warn("check active code falied , message:" + message);
/* 161 */       jsonObject.put("error", "1");
/* 162 */       jsonObject.put("msg", message);
/*     */     }
/*     */ 
/* 165 */     out.println(jsonObject);
/* 166 */     out.flush();
/* 167 */     out.close();
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.ActiveCodeChecker
 * JD-Core Version:    0.6.1
 */